
$(function(){
    $(".upload-btn").uploadify({
        height: 15,
        swf: ctx+'/home/assets/uploadify/img/uploadify.swf',
        uploader: ctx+'/order/uploadCommentPhoto.do',
        buttonText: '选择图片',
        'fileTypeExts': '*.gif; *.jpg; *.jpeg; *.bmp,*.gif',
        width: 60,
        auto: true,
        fileSizeLimit: '2MB',
        'fileObjName':'file',
        queueSizeLimit: 1,
        onInit: function () {
            $('.uploadify-button').addClass('btn btn-primary').css("-webkit-box-sizing", "content-box").css("box-sizing", "content-box");
            $('.uploadify-button').siblings('object').css("height", $('.uploadify-button').outerHeight());
            $('.uploadify-button').siblings('object').css("width", $('.uploadify-button').outerWidth());
        },
        'onUploadSuccess' : function(file, data, response) {
            data = eval('('+data+')');
            $('#photoList').append('<a href="JavaScript:;">' +
                '<img width="100%" height="100%" class="commentPhoto" sourceId="'+data.photoId+'" src="'+ctx+'/resource/download.do?id='+data.photoId+'" />' +
                '</a>');
            $('#imageNum').html(parseInt($('#imageNum').html())+1);
            if($('#imageNum').html()=="5")
                $("#image").uploadify('disable', true);
        }
    });

    $("#submitComment").click(function(){
        var orderGood,content,score,packing,deliverSpeed,serviceAttitude,photoIds;
        orderGood = $("#orderGoodId").val();
        content = $("#content").val();
        if($.trim(content)==""){
            alert("商品评价不能为空");
            return;
        }
        score = $("#score").val();
        if(score==0){
            alert("请对商品进行评分")
            return;
        }
        packing = $("#packing").val();
        if(packing==0){
            alert("请对商品包装进行评分")
            return;
        }
        deliverSpeed = $("#deliverSpeed").val();
        if(deliverSpeed==0){
            alert("请对送货速度进行评分")
            return;
        }
        serviceAttitude = $("#serviceAttitude").val();
        if(serviceAttitude==0){
            alert("请对服务态度进行评分")
            return;
        }
        photoIds = "";
        $('[sourceId]').each(function(){photoIds = photoIds+","+$(this).attr("sourceId")});
        if(photoIds.length>0)
            photoIds = photoIds.substr(1);
        $.ajax({
           url:ctx+"/comment/add.do",
            data: {
                orderGood:orderGood,
                content:content,
                score:score,
                packing:packing,
                deliverSpeed:deliverSpeed,
                serviceAttitude:serviceAttitude,
                photoIds:photoIds
            },
            success: function (data) {
                if(data.flag>0)
                    alert("提交成功");
            }
        });
    });
});


